﻿using smforj.common.model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;

namespace ConsoleApplication1
{
    class Program
    {  
        const int numIterations = 550;
        static AutoResetEvent myResetEvent = new AutoResetEvent(false);
        static AutoResetEvent ChangeEvent = new AutoResetEvent(false);
        //static ManualResetEvent myResetEvent = new ManualResetEvent(false);
        //static ManualResetEvent ChangeEvent = new ManualResetEvent(false);
        static int number; //这是关键资源

        static List<WardRobe> list = new List<WardRobe>();
        static List<WardRobe> list2 = new List<WardRobe>();

        static void Main(string[] args)
        {
            //DateTime date = DateTime.Now;
            //list.Add(new WardRobe() { RFID = "1", FirstReadTime = date, ReadTime = date });
            //list.Add(new WardRobe() { RFID = "2", FirstReadTime = date, ReadTime = date });
            //list.Add(new WardRobe() { RFID = "3", FirstReadTime = date, ReadTime = date });

            //WardRobe wr = list.Find(delegate(WardRobe _wr) { return _wr.RFID == "2"; });
            //Thread.Sleep(1000*3);
            //wr.ReadTime = DateTime.Now;
            //list2.Add(list[0]);
            //foreach (WardRobe wwr in list)
            //    Console.WriteLine("list: "+wwr.ReadTime);


            //list.Clear();
            //foreach (WardRobe wwr in list2)
            //    Console.WriteLine("list2: " + wwr.ReadTime);

            //foreach (WardRobe wwr in list)
            //    Console.WriteLine("list: " + wwr.ReadTime);


            string sRegex = @"(((([?](\w)+){1}[=]*))*((\w)+){1}([\&](\w)+[\=](\w)+)*)*";
            Regex myrx = new Regex(sRegex);
            Match match = myrx.Match("http://www.hao123.com//resource/1.jpg");
            if (!match.Success)
            {
                Console.Write("网址输入有错");
            }
            else
            {
                Console.Write("网址正确");
            }

            String str1 = "5";
            String str2 = "4";
            String str3 = "12";

            Console.WriteLine(str2.CompareTo(str1));
            Console.WriteLine(str2.CompareTo(str3));


            Console.ReadLine();
        }

        static void PayTest()
        {
            Thread payMoneyThread = new Thread(new ThreadStart(PayMoneyProc));
            payMoneyThread.Name = "付钱线程";
            Thread getBookThread = new Thread(new ThreadStart(GetBookProc));
            getBookThread.Name = "取书线程";
            payMoneyThread.Start();
            getBookThread.Start();

            for (int i = 1; i <= numIterations; i++)
            {
                //Console.WriteLine("买书线程：数量{0}", i);
                number = i;
                //Signal that a value has been written.
                myResetEvent.Set();
                ChangeEvent.Set();
                Thread.Sleep(0);
            }
            payMoneyThread.Abort();
            getBookThread.Abort();
        }

        static void PayMoneyProc()
        {
            while (true)
            {
                myResetEvent.WaitOne();
                //myResetEvent.Reset();
                Console.WriteLine("{0}：数量{1}", Thread.CurrentThread.Name, number);
            }
        }
        static void GetBookProc()
        {
            while (true)
            {
                ChangeEvent.WaitOne();
                // ChangeEvent.Reset();               
                Console.WriteLine("{0}：数量{1}", Thread.CurrentThread.Name, number);
                Console.WriteLine("------------------------------------------");
                Thread.Sleep(0);
            }
        } 
    }
}
